package com.linkai.blibli2021.blibli2;

import java.util.*;

class Solution {
    /* Write Code Here */
    public String reorder(String a, String b) {

        // 转换成为字符数组
        char[] aChars = a.toCharArray();
        char[] bChars = b.toCharArray();

        // 1. 首先在 a 字符串中找出和 b字符串相同的字符串
        int charIndex[] = new int[26];        // 最多26个字符
        ArrayList<Integer> arrayList = new ArrayList<>();

        for (int i =0; i < a.length(); i++) {
            for (int j = 0; j < b.length(); j++) {
                // 将当前字符a的下标存入 ArrayList 中
                if (aChars[i] == bChars[j]) {
                    arrayList.add(i);
                }
            }
        }

        // 2. 对数组a进行调整; i 是对数组b进行遍历
        for (int i = 0; i < b.length(); i++) {
            for (int j = 0; j < a.length(); j++) {
                if (bChars[i] == aChars[j]) {
                    // 将当前 a 中 i 指向的元素和 a中下标为 arrayList[j] 的元素进行交互位置
                    char tempChar = aChars[arrayList.get(j)];
                    aChars[arrayList.get(j)] = aChars[i];
                    aChars[i] = tempChar;
                }
            }
        }

        String str = String.valueOf(aChars);

        return str;
    }
}

public class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        String res;
            
        String _a;
        try {
            _a = in.nextLine();
        } catch (Exception e) {
            _a = null;
        }
        
        String _b;
        try {
            _b = in.nextLine();
        } catch (Exception e) {
            _b = null;
        }
  
        res = new Solution().reorder(_a, _b);
        System.out.println(res);
    }
}
